﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Serverslist
{
    class Web
    {
        //0. fields .. 
        string serverspage;
        
        //1. property. 
        public string _serverpage
        {

            get { return serverspage; }
            set { serverspage = value; }
        }
        //2. methode ..
        public string getserverpage(string link)
        {
            
            WebRequest request = WebRequest.Create(link);
            request.Method = "GET";
            WebResponse response = request.GetResponse();
            Stream stream = response.GetResponseStream();
            StreamReader reader = new StreamReader(stream);
            string  content = reader.ReadToEnd();
            reader.Close();
            response.Close();

            return content;
        }
        public string GET(String url, CookieContainer cki)
        {
            try
            {
                //create new request
                HttpWebRequest rq1 = (HttpWebRequest)HttpWebRequest.Create(url);
                String htmlSource = "";

                //prepare headers
                rq1.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24";
                rq1.ContentType = "application/x-www-form-urlencoded";
                rq1.AllowAutoRedirect = false;
                rq1.UseDefaultCredentials = true;
                rq1.KeepAlive = true;
                
                rq1.Method = "GET";
               

                //get source code html  and cookie
                HttpWebResponse resp = (HttpWebResponse)rq1.GetResponse();
                StreamReader sr = new StreamReader(resp.GetResponseStream());
                htmlSource = sr.ReadToEnd();
                

               
                sr.Close();
                resp.Close();

             
                

                //return source html                
                return htmlSource;
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                return "";
            }
        }
    }

}
